<template>
  <div class="home">
    <!-- 背景阴影 -->
    <div class="bg-mask" :style="getBackgroundImage" />

    <!-- 导航和轮播 -->
    <div class="home-container m-center">
      <home-nav />
      <mooc-carousel :height="316" trigger="click" @change="handelCarouselChange">
        <mooc-carousel-item v-for="(item,index) in swiperList" :key="index">
          <img :src="item.img" class="swiper-img">
        </mooc-carousel-item>
      </mooc-carousel>

      <home-banner />
    </div>

    <!--  实战导航 -->
    <course-list :course="practiceList" />

    <!-- 新手入门 -->
    <course-list :course="guideList" />

    <!-- 技能提升 -->
    <course-list :course="improveList" />

    <!-- 猿问和手记 -->
    <home-article :article="articleList" />

  </div>
</template>
<script>
import HomeNav from './home-nav.vue'
import HomeBanner from './home-banner.vue'
import CourseList from './home-course-list.vue'
import HomeArticle from './home-article.vue'
import { getHomeCourse, getArticle } from 'api/home.js'
import { ERR_OK } from 'api/config.js'
export default {
  name: 'Home',
  data () {
    return {
      swiperList: [], //首页轮播信息
      allstar: [], // 全明星
      articleList: {}, // 猿问和手记
      improveList: {}, // 技能提升
      guideList: {}, // 新手入门
      practiceList: {}, // 实战课程
      currentSwiper: '' // 当前的轮播图片
    }
  },
  created () {
    this.getBanner()
    this.getCourseList()
    this.getArticleList()
  },
  methods: {
    // 滚动轮播滚动完毕事件
    handelCarouselChange (index) {
      this.currentSwiper = this.swiperList[index].img
    },
    // 首页轮播信息
    getBanner () {
      this.swiperList = [
        {
          "id": 1,
          "img": "https://img.mukewang.com/5d1e0a1800013ca916000540.jpg"
        },
        {
          "id": 2,
          "img": "https://img.mukewang.com/5d1c5aec00011c1016000540.jpg" },
        {
          "id": 3,
          "img": "https://img.mukewang.com/5d108b1500010bfe18720632.jpg" },
        {
          "id": 4,
          "img": "https://img.mukewang.com/5d1466c5000172a516000540.jpg" },
        {
          "id": 5,
          "img": "https://img.mukewang.com/5cb833cf0001efb716000540.jpg" },
        {
          "id": 6,
          "img": "https://img.mukewang.com/5c0fd2630001ef2118720632.jpg"
        }
      ]
      this.currentSwiper = this.swiperList[0].img
    },
    // 获取课程信息
    getCourseList () {
      getHomeCourse().then(res => {
        let { code, data } = res
        if (code === ERR_OK) {
          let practice = {
            title: '实战推荐',
            leftIcon: "center 0px",
            rightIcon: "center -36px",
            data: data.实战
          }
          this.practiceList = practice
          let guide = {
            title: '新手入门',
            leftIcon: "center -144px",
            rightIcon: "center -180px",
            data: data.初级
          }
          this.guideList = guide
          let improve = {
            title: '技能提升',
            leftIcon: "center -216px",
            rightIcon: "center -252px",
            data: data.中级
          }
          this.improveList = improve
        }
      })
    },
    // 获取猿问和手记
    getArticleList () {
      getArticle().then((res) => {
        let { code, data } = res
        if (code === ERR_OK) {
          this.articleList = data
        }
      })
    },
  },
  computed: {
    getBackgroundImage () {
      return {
        'background-image': `url(${this.currentSwiper})`
      }
    }
  },
  components: {
    HomeNav,
    HomeBanner,
    CourseList,
    HomeArticle
  }
}
</script>
<style lang="stylus" scoped>
  @import '~assets/stylus/variables.styl';
  .home
    margin-top: 32px;
    min-height: 750px;
    .bg-mask
      position: absolute;
      top: 0;
      background-size: cover;
      transition: all 0.3s;
      width: 100%;
      height: 180px;
      opacity: 0.3;
      filter: blur(100px);
    .home-container
      position: relative;
      box-shadow: 0 12px 24px 0 $shadow;
      border-radius: 8px;
      .mooc-carousel
        position: absolute;
        left: 216px;
        top: 0;
        right: 0;
        >>> .mooc-carousel-indicators
          left: initial;
          right: 20px;
          transform: none;
        .swiper-img
          display: block;
          width: 100%;
          height: 316px;
          border-top-right-radius: 8px;
</style>
